/**
 * 数据库相关操作
 * 
 */

let model = {

    query: function (sql,value) {
        let mysql = require("mysql");

        let connection = mysql.createConnection({ host: 'localhost', user: 'root', password: 'root', database: 'yiqing', port: '3306' });

        connection.connect();

        connection.query(sql, value, function (err, result) {

            console.log(result);
            //对数据进行处理
            //构建html 展示给用户
            //
            let html='<div>';
            for(let val in result){
                console.log(result[val].city);
                console.log(result[val].nums);
                 html+='<div class="city">'+result[val].city+'</div>';
                 html+='<div class="nums">'+result[val].nums+'</div>';

            }
            html+="</div>"

        })

        connection.end();
    }

}



module.exports =model
